//
//  KKPublishXuanShangVC.m
//  DoMi
//
//  Created by 康凯 on 2016/12/6.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKPublishXuanShangVC.h"
#import "UIViewController+BackButtonHandler.h"
#import "KKUploadUtils.h"
#import "KKUploadDialog.h"
#import "KKTxtContentM.h"
#import "KKImgSectionCell.h"
#import "KKArticleSectionCell.h"
#import "KKSendArticleDialog.h"
#import "KKComHttp.h"
#import "KKPayDialog.h"
#import "KKPayDialog.h"
#import "KKPayInfoM.h"
#import "WXApi.h"
#import <AlipaySDK/AlipaySDK.h>
#import "KKPublishXuanShangDialog.h"
#define ALIPAY_SCHEMA @"KKDoMiAlipay"
#import "IQKeyboardManager.h"

@interface KKPublishXuanShangVC ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,UITextViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,BackButtonHandlerProtocol>

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UITextField *questionTitle;
@property (weak, nonatomic) IBOutlet UITextField *label;
@property (weak, nonatomic) IBOutlet UITextView *questionContent;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIView *hotTagView;
@property (weak, nonatomic) IBOutlet UIView *oftenTagView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrollContentView;
@property (strong, nonatomic) UIImagePickerController *imagePicker;
@property (strong, nonatomic) KKUploadUtils *uploadUtils;
@property (weak, nonatomic) IBOutlet UIView *saveDraftView;

@property (weak, nonatomic) IBOutlet UIView *xuanShangPriceView;
@property (weak, nonatomic) IBOutlet UIView *selectDateView;
@property (weak, nonatomic) IBOutlet UIDatePicker *datePicker;
@property (weak, nonatomic) IBOutlet UIButton *startDate;
@property (weak, nonatomic) IBOutlet UIButton *endDate;
@property (weak, nonatomic) IBOutlet UITextField *inputPrice;


@property(strong,nonatomic)NSMutableArray *questionDatas;
@property(copy,nonatomic)NSString *contentType;
@property(copy,nonatomic)NSString *editType;
@property(copy,nonatomic)NSString *editSectionId;
@property(copy,nonatomic)NSString *editDocId;
@property(copy,nonatomic)NSString *questionId;
@property(copy,nonatomic)NSString *content;
@property(assign,nonatomic)CGFloat totalHeight;

@property(strong,nonatomic)NSMutableArray *priceLabels;
@property(assign,nonatomic)int selectDateType;
@property(copy,nonatomic)NSString *selectPrice;
@property(copy,nonatomic)NSString *payType;
@property(copy,nonatomic)NSString *aliOrder;
@property(strong,nonatomic)KKPayInfoM *wxOrder;
@property(strong,nonatomic)NSArray *hotLabels;
@property(strong,nonatomic)NSArray *usedLabels;
@property(strong,nonatomic)NSMutableString *selectLabels;
@property(assign,nonatomic)NSTimeInterval startTime;
@property(assign,nonatomic)int count;
@end

@implementation KKPublishXuanShangVC
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [IQKeyboardManager sharedManager].enable = YES;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [IQKeyboardManager sharedManager].enable = NO;
}
-(NSMutableString *)selectLabels{
    if(!_selectLabels){
        _selectLabels=[NSMutableString string];
    }
    return _selectLabels;
}
-(NSMutableArray *)priceLabels{
    if(!_priceLabels){
        _priceLabels=[NSMutableArray arrayWithObjects:@"10",@"50",@"100",@"200",@"500",@"1000", nil];
    }
    return _priceLabels;
}

-(NSMutableArray *)questionDatas{
    if(!_questionDatas){
        _questionDatas=[NSMutableArray array];
    }
    return _questionDatas;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"发布悬赏";
    [self initView];
}

-(void)initView{
    NSNotificationCenter *center=[NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(wXPayNotice:) name:@"wxPaySuccess" object:nil];
    //tableview
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    [self.tableView registerNib:[UINib nibWithNibName:@"KKArticleSectionCell" bundle:nil] forCellReuseIdentifier:@"KKArticleSectionCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"KKImgSectionCell" bundle:nil] forCellReuseIdentifier:@"KKImgSectionCell"];
    
    //scrollview
    self.scrollView.delegate=self;
    
    self.questionContent.delegate=self;
    self.questionId=@"";
    //图片选择
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    self.imagePicker=imagePicker;
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    
    self.uploadUtils=[[KKUploadUtils alloc] init];
    __weak typeof(self) weakSelf=self;
    self.uploadUtils.uploadBlock=^(NSString *url){
        KKLog(@"url---->%@",url);
        weakSelf.content=url;
        if([weakSelf.editType isEqualToString:@"1"]){
            [weakSelf modifyArticle:weakSelf.editDocId sectionId:weakSelf.editSectionId];
        }else{
            [weakSelf addQuestion];
        }
        
    };
    self.editType=@"0";
    //悬赏标签
    for (int i=0; i<self.priceLabels.count; i++) {
        int perHeight=i/3;
        float perWidth=(screenWidth-20-30)/3;
        float width;
        float height;
        if(i%3==0){
            width=perWidth;
        }else{
            width=perWidth+10;
        }
        if(i==0){
            height=35;
        }else{
            height=45;
        }
        
        UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(i%3*width, perHeight*height, perWidth, 35)];
        btn.layer.cornerRadius=2;
        btn.tag=i;
        [btn setTitle:[NSString stringWithFormat:@"¥%@",self.priceLabels[i]] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(selectPriceClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.backgroundColor=[UIColor colorWithHexString:@"#343536"];
        [self.xuanShangPriceView addSubview:btn];
    }
    //时间选择
    [self.datePicker setLocale:[NSLocale currentLocale]];
//    [self.datePicker addTarget:self action:@selector(selectDate:) forControlEvents:UIControlEventValueChanged];
    [self getLabelList];
    self.count=0;
}
#pragma mark 初始化标签
-(void)initLabels{
    //热门标签
    float perWidth=self.hotTagView.frame.size.width/4;
    for (int i=0; i<self.hotLabels.count; i++) {
        int perHeight=i/4;
        UIButton *historyItem=[[UIButton alloc] initWithFrame:CGRectMake(i%4*perWidth, perHeight*30, perWidth, 30)];
        historyItem.tag=i;
        historyItem.layer.shadowColor=[UIColor blackColor].CGColor;
        historyItem.layer.shadowOpacity=0.7;
        historyItem.layer.shadowOffset=CGSizeMake(0,0);
        NSDictionary *title=self.hotLabels[i];
        [historyItem setTitle:title[@"title"] forState:UIControlStateNormal];
        [historyItem addTarget:self action:@selector(setHotLabel:) forControlEvents:UIControlEventTouchUpInside];
        [self.hotTagView addSubview:historyItem];
    }
    //常用标签
    for (int i=0; i<self.usedLabels.count; i++) {
        int perHeight=i/4;
        UIButton *historyItem=[[UIButton alloc] initWithFrame:CGRectMake(i%4*perWidth, perHeight*30, perWidth, 30)];
        historyItem.tag=i;
        historyItem.layer.shadowColor=[UIColor blackColor].CGColor;
        historyItem.layer.shadowOpacity=0.7;
        historyItem.layer.shadowOffset=CGSizeMake(0,0);
        NSDictionary *title=self.usedLabels[i];
        [historyItem setTitle:title[@"title"] forState:UIControlStateNormal];
        [historyItem addTarget:self action:@selector(setUseLabel:) forControlEvents:UIControlEventTouchUpInside];
        [self.oftenTagView addSubview:historyItem];
    }
}

#pragma mark 展示上传对话框
-(void)showUploadDialog{
    KKUploadDialog *upload=[[[NSBundle mainBundle] loadNibNamed:@"KKUploadDialog" owner:self options:nil] lastObject];
    upload.uploadBlock=^(int flag){
        if(flag==1){
            self.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
        }else if(flag==2){
            self.imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
        }
        [self presentViewController:self.imagePicker animated:YES completion:nil];
    };
    [upload show];
}

#pragma mark 监听系统返回事件
-(BOOL)navigationShouldPopOnBackButton{
    if([KKAppUtils isEmptyString:self.questionId]){
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"提示" message:@"确定退出编辑吗？" preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:alert animated:YES completion:nil];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self.navigationController popViewControllerAnimated:YES];
        }]];
    }
    return NO;
}

#pragma mark datePicker代理

#pragma mark imagepicker代理
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    NSString *mediaType=[info objectForKey:UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:@"public.image"]){
        //如果是图片
        UIImage *selectImg= info[UIImagePickerControllerEditedImage];;
        //压缩图片
        NSData *fileData = UIImageJPEGRepresentation(selectImg, 1.0);
        //保存图片至相册
        //        UIImageWriteToSavedPhotosAlbum(selectImg, self,nil, NULL);
        [self.uploadUtils uploadObjectAsync:fileData];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark textview代理
-(void)textViewDidBeginEditing:(UITextView *)textView{
    if([textView.text isEqualToString:@"请输入悬赏内容"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}
-(void)textViewDidEndEditing:(UITextView *)textView{
    if(textView.text.length < 1){
        textView.text = @"请输入悬赏内容";
        textView.textColor = [UIColor grayColor];
    }
}

#pragma mark tableview代理
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    KKTxtContentM *content=self.questionDatas[indexPath.row];
    //0图片1文字
    if([content.contenttype isEqualToString:@"0"]){
        KKImgSectionCell *img=(KKImgSectionCell *)cell;
        img.modifyBlock=^(){
            self.editType=@"1";
            self.editSectionId=content.id;
            self.editDocId=content.questionid;
            [self showUploadDialog];
        };
        img.upMoveBlock=^(){
            [self upMoveArticle:content.questionid sectionId:content.id];
        };
        img.downMoveBlock=^(){
            [self downMoveArticle:content.questionid sectionId:content.id];
        };
        img.delBlock=^(){
            [self delArticle:content.questionid sectionId:content.id];
        };
    }else{
        KKArticleSectionCell *doc=(KKArticleSectionCell *)cell;
        doc.modifyBlock=^(){
            self.editType=@"1";
            self.questionContent.text=content.content;
            self.editSectionId=content.id;
            self.editDocId=content.questionid;
        };
        doc.upMoveBlock=^(){
            [self upMoveArticle:content.questionid sectionId:content.id];
        };
        doc.downMoveBlock=^(){
            [self downMoveArticle:content.questionid sectionId:content.id];
        };
        doc.delBlock=^(){
            [self delArticle:content.questionid sectionId:content.id];
        };
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _questionDatas.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    KKTxtContentM *content=self.questionDatas[indexPath.row];
    if([content.contenttype isEqualToString:@"0"]){
        KKImgSectionCell *cell=[tableView dequeueReusableCellWithIdentifier:@"KKImgSectionCell"];
        [cell initData:content.content];
        return cell;
    }else{
        KKArticleSectionCell *cell=[tableView dequeueReusableCellWithIdentifier:@"KKArticleSectionCell"];
        [cell initData:content.content];
        return cell;
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    KKTxtContentM *content=self.questionDatas[indexPath.row];
    if([content.content containsString:@"http://dmyjr.oss-cn-beijing.aliyuncs.com"]){
        return 105;
    }else{
        return content.contentSize.height+10;
    }
}
#pragma mark 通知接受
-(void)wXPayNotice:(NSNotificationCenter *)center{
    self.count++;
    if(self.count==1){
        KKPublishXuanShangDialog *publish=[[[NSBundle mainBundle] loadNibNamed:@"KKPublishXuanShangDialog" owner:self options:nil] lastObject];
        publish.confirmClickBlock=^(){
            self.publishSuccessBlock();
            [self.navigationController popViewControllerAnimated:YES];
        };
        [publish show];
    }
}

#pragma mark 按钮--选择悬赏金额
-(void)selectPriceClick:(UIButton *)btn{
    self.inputPrice.text=self.priceLabels[btn.tag];
}

#pragma mark 按钮--时间选择器值改变
//-(void)selectDate:(UIDatePicker *)date{
//    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
//    [formatter setDateFormat:@"yyyy-MM-dd"];
//    if(self.selectDateType==0){
//        [self.startDate setTitle:[formatter stringFromDate:date.date] forState:UIControlStateNormal];
//    }else{
//        [self.endDate setTitle:[formatter stringFromDate:date.date] forState:UIControlStateNormal];
//    }
//}
#pragma mark 按钮--选择时间完成
- (IBAction)selectDateFinishClick:(id)sender {
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    if(self.selectDateType==0){
        NSTimeInterval currentTime=[[NSDate date] timeIntervalSince1970];
        self.startTime=[self.datePicker.date timeIntervalSince1970];
        if(self.startTime<currentTime){
            [self toast:@"请选择正确时间"];
            return;
        }
        [self.startDate setTitle:[formatter stringFromDate:self.datePicker.date] forState:UIControlStateNormal];
    }else{
        NSTimeInterval endTime=[self.datePicker.date timeIntervalSince1970];
        if(endTime<self.startTime){
            [self toast:@"请选择正确时间"];
            return;
        }
        [self.endDate setTitle:[formatter stringFromDate:self.datePicker.date] forState:UIControlStateNormal];
    }
    self.selectDateView.hidden=YES;
}
#pragma mark 按钮--热门标签
-(void)setHotLabel:(UIButton *)btn{
    NSDictionary *title=self.hotLabels[btn.tag];
    if([self.selectLabels containsString:title[@"title"]]){
        [self toast:@"以选择该标签"];
    }else{
        [self.selectLabels appendFormat:@"#%@;",title[@"title"]];
        self.label.text=self.selectLabels;
    }
}
#pragma mark 按钮--常用标签
-(void)setUseLabel:(UIButton *)btn{
    NSDictionary *title=self.usedLabels[btn.tag];
    if([self.selectLabels containsString:title[@"title"]]){
        [self toast:@"以选择该标签"];
    }else{
        [self.selectLabels appendFormat:@"#%@;",title[@"title"]];
        self.label.text=self.selectLabels;
    }
}
#pragma mark 按钮--确认发布
- (IBAction)confirmClick:(id)sender {
    if([KKAppUtils isEmptyString:self.questionId]){
        [self toast:@"请先发布段落内容"];
        return;
    }
    if([KKAppUtils isEmptyString:self.inputPrice.text]){
        [self toast:@"请输入或选择悬赏金额"];
        return;
    }
    float price=[self.inputPrice.text floatValue];
    if(price!=0&&price<1){
        [self toast:@"悬赏金额不能低于1元"];
        return;
    }
    if(![self.inputPrice.text isEqualToString:@"0"]){
        if([KKAppUtils isEmptyString:self.startDate.titleLabel.text]){
            [self toast:@"请选择开始时间"];
            return;
        }
        if([KKAppUtils isEmptyString:self.endDate.titleLabel.text]){
            [self toast:@"请选择结束时间"];
            return;
        }
    }
    if([self.inputPrice.text isEqualToString:@"0"]){
        self.payType=@"";
        self.startDate.titleLabel.text=@"";
        self.endDate.titleLabel.text=@"";
        [self publishQuestion];
    }else{
        KKPayDialog *pay=[[[NSBundle mainBundle] loadNibNamed:@"KKPayDialog" owner:self options:nil] lastObject];
        pay.payTypeBlock=^(NSString *type){
            self.payType=type;
            [self publishQuestion];
        };
        [pay show];
    }
}
- (IBAction)dismissSelectTime:(id)sender {
    self.selectDateView.hidden=YES;
}

#pragma mark 按钮--只提问不悬赏
- (IBAction)questionNoXuanShangClick:(id)sender {
    self.inputPrice.text=@"0";
}
#pragma mark 按钮--开始时间
- (IBAction)startDateClick:(id)sender {
    self.selectDateType=0;
    self.selectDateView.hidden=NO;
}
#pragma mark 按钮--结束时间
- (IBAction)endDateClick:(id)sender {
    if(self.startTime==0){
        [self toast:@"请先选择开始时间"];
        return;
    }
    self.selectDateType=1;
    self.selectDateView.hidden=NO;
}


#pragma mark 按钮--添加文字
- (IBAction)addDocumentClick:(id)sender {
    if([KKAppUtils isEmptyString:self.questionTitle.text]){
        [self toast:@"请输入悬赏标题"];
        return;
    }
    if([KKAppUtils isEmptyString:self.label.text]){
        [self toast:@"请输入悬赏标签"];
        return;
    }
    if([self.questionContent.text isEqualToString:@"请输入悬赏内容"]){
        [self toast:@"请输入悬赏内容"];
        return;
    }
    if([KKAppUtils isEmptyString:self.questionContent.text]){
        [self toast:@"请输入悬赏标签"];
        return;
    }
    self.content=self.questionContent.text;
    self.contentType=@"1";
    if([self.editType isEqualToString:@"1"]){
        [self modifyArticle:self.editDocId sectionId:self.editSectionId];
    }else{
        [self addQuestion];
    }
    
}
#pragma mark 按钮--添加图片
- (IBAction)addDocumentImg:(id)sender {
    [self.view endEditing:YES];
    if([KKAppUtils isEmptyString:self.questionTitle.text]){
        [self toast:@"请输入悬赏标题"];
        return;
    }
    if([KKAppUtils isEmptyString:self.label.text]){
        [self toast:@"请输入悬赏标签"];
        return;
    }
    self.contentType=@"0";
    [self showUploadDialog];
}

#pragma mark 接口--文章详情
-(void)getQuestionContentList{
    [KKComHttp getQuestionContentList:self.questionId success:^(id data) {
        [self.questionDatas removeAllObjects];
        NSArray *list=[data objectForKey:@"listcontent"];
        NSArray *datas=[KKTxtContentM mj_objectArrayWithKeyValuesArray:list];
        [self.questionDatas addObjectsFromArray:datas];
        self.totalHeight=0;
        for (KKTxtContentM *content in self.questionDatas) {
            if([content.contenttype isEqualToString:@"1"]){
                self.totalHeight+=content.contentSize.height+10;
            }else{
                self.totalHeight+=100;
            }
        }
        self.tableViewHeight.constant=self.totalHeight;
        self.scrollContentView.constant=920+self.totalHeight;
        
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark 接口--发布问题
-(void)publishQuestion{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"questionid":self.questionId,@"startdate":self.startDate.titleLabel.text,@"enddate":self.endDate.titleLabel.text,@"money":self.inputPrice.text,@"paytype":self.payType};
    [KKComHttp publishQuestion:params success:^(id data) {
        NSString *code=[data objectForKey:@"code"];
        if([code isEqualToString:@"ok"]){
            [self toast:@"发布成功"];
            self.publishSuccessBlock();
            [self.navigationController popViewControllerAnimated:YES];
        }else if([code isEqualToString:@"payorder"]){
            NSString *orderInfo=[data objectForKey:@"orderinfo"];
            if([self.payType isEqualToString:@"wx"]){
                KKPayInfoM *payInfo=[KKPayInfoM mj_objectWithKeyValues:orderInfo];
                //调起微信支付
                PayReq* req = [[PayReq alloc] init];
                req.partnerId = payInfo.partnerid;
                req.prepayId = payInfo.prepayid;
                req.nonceStr = payInfo.noncestr;
                req.timeStamp = payInfo.timestamp.intValue;
                req.package = payInfo.package;
                req.sign = payInfo.sign;
                [WXApi sendReq:req];
            }else{
                KKLog(@"order--->%@",orderInfo);
                [[AlipaySDK defaultService] payOrder:orderInfo fromScheme:ALIPAY_SCHEMA callback:^(NSDictionary *resultDic) {
                    NSLog(@"reslut = %@",resultDic);
                }];
            }
        }else{
            NSString *msg=[data objectForKey:@"msg"];
            [self toast:msg];
        }
        [self dismissDialog];

    } failure:^(NSError *error) {
        [self dismissDialog];
    }];
}
#pragma mark 接口--新增悬赏段落
-(void)addQuestion{
    [self showDialog];
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"questionid":self.questionId,@"title":self.questionTitle.text,@"lable":self.label.text,@"content":self.content,@"contenttype":self.contentType};
    
    [KKComHttp addQuestion:params success:^(id data) {
        self.questionId=data;
        if([self.contentType isEqualToString:@"1"]){
            self.questionContent.text=@"";
        }
        
        [self dismissDialog];
        [self toast:@"段落添加成功"];
        if(![KKAppUtils isEmptyString:self.questionId]){
            [self getQuestionContentList];
        }
    } failure:^(NSError *error) {
        [self dismissDialog];
    }];
}
#pragma mark 接口--编辑段落
-(void)modifyArticle:(NSString *)docId sectionId:(NSString *)sectionId{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"questionid":docId,@"id":sectionId,@"content":self.content};
    [KKComHttp modifyQuestion:params success:^(id data) {
        self.editType=@"0";
        if([self.contentType isEqualToString:@"1"]){
            self.questionContent.text=@"";
        }
        [self toast:@"修改成功"];
        [self getQuestionContentList];
    } failure:^(NSError *error) {
        
    }];
    
}
#pragma mark 接口--上移段落
-(void)upMoveArticle:(NSString *)docId sectionId:(NSString *)sectionId{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"questionid":docId,@"id":sectionId};
    [KKComHttp upMoveQuestion:params success:^(id data) {
        [self toast:@"上移成功"];
        [self getQuestionContentList];
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 接口--下移段落
-(void)downMoveArticle:(NSString *)docId sectionId:(NSString *)sectionId{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"questionid":docId,@"id":sectionId};
    [KKComHttp downMoveQuestion:params success:^(id data) {
        [self toast:@"下移成功"];
        [self getQuestionContentList];
    } failure:^(NSError *error) {
        
    }];
    
}
#pragma mark 接口--删除段落
-(void)delArticle:(NSString *)docId sectionId:(NSString *)sectionId{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"questionid":docId,@"id":sectionId};
    [KKComHttp delQuestion:params success:^(id data) {
        [self toast:@"删除成功"];
        [self getQuestionContentList];
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 接口--标签列表
-(void)getLabelList{
    [self showDialog];
    [KKComHttp getLabelList:^(id data) {
        self.hotLabels=[data objectForKey:@"hotlabels"];
        self.usedLabels=[data objectForKey:@"usedlabels"];
        [self initLabels];
        [self dismissDialog];
    } failure:^(NSError *error) {
        [self dismissDialog];
    }];
}



@end
